<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'mobile_phone', 'region', 'city', 'openid', 'gender', 'is_contact'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array   
     */
    protected $hidden = [
        'password', 'remember_token', 'api_token'
    ];


    /**
    * check if user has validated both their email and phone
    */
    public function isCertified() {

        if (!$this->is_phone_valid) {
            return false;
        }

        return true;
    }

    static public function setDefaultLocale($request) {
        $allLanguage = $request->header('accept-language');
        $language = explode(',',$allLanguage);
        $language = $language[0];
        if ($request->session()->has('locale')) {
            $language = $request->session()->get('locale');
        }
        switch($language)
        {
            case 'zh':
                App::setLocale('zh');
                break;
            case 'zh-CN':
                App::setLocale('zh');
                break;
            case 'en':
                App::setLocale('en');
                break;
            case 'en-US':
                 App::setLocale('en');
                break;
            default:
                App::setLocale('en');
        }
    }

}
